package com.my.server2.controller;

import com.my.server2.entity.Goods;
import com.my.server2.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/s2")
public class ProviderController {
    @Autowired
    private GoodsService goodsService;
    @RequestMapping("get")
    public String get(@RequestBody String id){
        String rs = "库存更新失败-->不发货";
        Goods goods = new Goods();
        System.out.println("adfafaddssdsdsd" + id);
        goods.setId(id);
        goods.setGoodRest(goodsService.getById(id).getGoodRest() - 1);
        goodsService.updateById(goods);
        int a = 1 / 0;  //抛出异常，测试事务回滚
        rs = "库存已更新-->准备发货end";
        return rs;
    }
}
